<?php
use \yii\helpers\Url;
use \yii\helpers\Html;
use \common\models\Catalog;
use \common\models\Post;
use \common\models\Banner;
use \common\models\Links;
use yii\widgets\ListView;
use yii\bootstrap\BootstrapAsset;
use yii\web\JqueryAsset;
?><!--catalog-->
<!--/* @description 在线留言 */-->


<table>
    <tr>
        <td>留言标题</td>
        <td><input type="text" id="title"/></td>
    </tr>
    <tr>
        <td>留言邮箱</td>
        <td><input type="text" id="email"/></td>
    </tr>
    <tr>
        <td>留言内容</td>
        <td><textarea id="content"></textarea></td>
    </tr>
</table>
<input type="button" value="提交" id="submit"/>
<?php
$script = <<<JS
    $("#submit").click(function () {
        var title = $("#title").val();
        var email = $("#email").val();
        var content = $("#content").val();
        var csrfToken = $('meta[name="csrf-token"]').attr("content");
        $.post("/message/save.html", {
            "Message[title]": title,
            "Message[email]": email,
            "Message[content]": content,
            _csrf: csrfToken
        }, function (result) {
            console.log(result);
            if (result.success == true) {
                window.location.reload();//刷新，也可以做跳转
            } else {
                alert(result.errors);
            }
        }, "json");
    });
JS;
$this->registerJs($script);
?>